<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onRowSelectChange="selectChange"
      columnsRef="jzySeries"
      :isExportExcel2="true"
      :exportFileName="'配件常规订购日历.xlsx'"
      :onColumnsChange="columns => this.columns = columns"
    >
    </FilterTable>
  </div>
</template>

<script>
import {dictionary} from '@/utils/dictMixin';
import {getpartcalendarlist} from '@/api/partsmanage/partordertype/index';
import {ddlxArr} from "../../purchaseManage/purchaseSubmit/constant";
import { getCurrentUser } from '@/api/cms-api/origin/construct/dealer';

const ydArr = [
  {text: '油车件', value: '1'},
  {text: '电车件', value: '2'},
];
export default {
  name: "index",
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: getpartcalendarlist,
      fetchParams: null,
      dialogTitle: '',
      visibleDrawer: false,
      title: '新增',
      type: '',
      formData: {},
      rowSelectData: [],
      showAddNew: false,
    };
  },
  async created() {
    // this.columns.find(x => x.dataIndex === 'sender').hidden = true;
    // this.columns.find(x => x.dataIndex === 'sender').dictItems = this.createDictList('5000');
    // 获取当前登录人信息
    await getCurrentUser({}).then(response => {
      console.info(response);
      if (response.data.appId === 'beijing') {
        console.info(this.topFilterList);
        this.topFilterList.find(x => x.fieldName === 'sender').hidden = false;
        // this.columns.find(x => x.dataIndex === 'sender').hidden = false;
      }
    });
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealCode'
        },
        {type: 'SELECT', label: '油电属性', fieldName: 'sender', hidden: true, placeholder: '请选择', itemList: ydArr},
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
        },
        {
          title: '油电属性',
          dataIndex: 'sender',
          dictItems: ydArr,
          sorter: true,
        },
        {
          title: '订购日期',
          dataIndex: 'orderdate',
          sorter: true,
        }
      ]
    },
    selectChange(val) {
      console.log('val', val);
      this.rowSelectData = val;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
}
</script>

<style scoped>

</style>
